﻿/*
 * Created by SharpDevelop.
 * User: hugo
 * Date: 2012/8/6
 * Time: 下午 10:37
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using MyPetShop.Domain;

namespace MyPetShop.Domain
{
	/// <summary>
	/// Description of Shopping.
	/// </summary>
	public class Shopping
	{
		public int Total {get;set;}
	    protected IList<ShoppingDetail> InnerShoppingDetail { get; set; }

	    public IEnumerable<ShoppingDetail> ShoppingDetails
	    {
	        get { return InnerShoppingDetail.AsEnumerable(); }
	    }
		
		public Shopping()
		{
            InnerShoppingDetail = new List<ShoppingDetail>();
		}
		
		public void ReCalculate()
		{
		}
		
		public void AddItem(Item item, int quantity)
		{
			ShoppingDetail shoppingDetail = new ShoppingDetail(item.ItemId,quantity);
            InnerShoppingDetail.Add(shoppingDetail);
            Total += 1;
		}
		
		public void RemoveItem(int itemId,int quantity)
		{
			var shoppingDetail 
				= ShoppingDetails.FirstOrDefault(s=>s.ItemId == itemId);

            InnerShoppingDetail.Remove(shoppingDetail);
            
            Total -= 1;
		}
	}
}
